package com.ruoyi.system.service.impl;

import com.ruoyi.system.domain.SysGoods;
import com.ruoyi.system.mapper.SysGoodsMapper;
import com.ruoyi.system.service.ISysGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class SysGoodsServiceImpl implements ISysGoodsService {

    @Autowired
    private SysGoodsMapper goodsMapper;


    @Override
    public List<SysGoods> selectSysGoodsList(SysGoods sysGoods) {
        List<SysGoods> sysGoods1 = goodsMapper.selectSysGoodsList(sysGoods);
        for (SysGoods goods : sysGoods1) {
            goods.setCreator(goodsMapper.findByName(goods.getCreator()));
        }
        return sysGoods1;
    }

    @Override
    public int insertSysGoods(SysGoods sysGoods) {
        sysGoods.setTime(new Date());
        sysGoods.setUpdatetime(new Date());
        return goodsMapper.insertSysGoods(sysGoods);
    }

    @Override
    public SysGoods selectSysGoodsById(Long id) {
        return goodsMapper.selectSysGoodsById(id);
    }

    @Override
    public int updateSysGoods(SysGoods sysGoods) {
        sysGoods.setTime(new Date());
        sysGoods.setUpdatetime(new Date());
        return goodsMapper.updateSysGoods(sysGoods);
    }

    @Override
    public int deleteSysGoodsByIds(String ids) {
        return goodsMapper.deleteSysGoodsByIds(ids);
    }

    @Override
    public Integer findId(String loginName) {
        return goodsMapper.findId(loginName);
    }
}
